<style>
    .refund-view-list{margin-top:20px;font-size:14px;line-height:20px;color:#323233;color:var(--theme-stroke-1,#323233)}
    .refund-view-item {margin-bottom: 10px;}
    /*!*display: -ms-flexbox;*!*//*!*display: flex;*!*/.refund-view-item-label{width:75px; vertical-align: top;}
    .refund-view-item-content{display:inline-block}
</style>
<!-- 店铺主动退款 -->
<script type="text/html" id="refund_transfer_html">
    <div style="padding:10px;">
        <div class="layui-form refund-transfer-html" id='refund_transfer'lay-filter="refund_transfer">
            <!--<div style="color: #666;">注意 : 当你确认转账后，退款将自动原路退回至买家付款账户。</div>-->
            <div class="refund-view-list">

                <div class="refund-view-item">
                    <label class="refund-view-item-label">退款金额：</label>
                    <div class="refund-view-item-content">
                        <span class="refund-money">
                            ￥{{ d.order_goods_info.refund_apply_money }}
                        </span>
                    </div>
                </div>
                <div class="refund-view-item">
                    <label class="refund-view-item-label">主动退款：</label>
                    <div class="refund-view-item-content">
                        <input type='text' class="layui-input" name="do_refund_money" value="">
                    </div>
                </div>
                {{# if(d.order_goods_info.use_point > 0){ }}
                <div class="refund-view-item">
                    <label class="refund-view-item-label">退还积分：</label>
                    <div class="refund-view-item-content">
                        <span class="refund-money">
                            {{ d.order_goods_info.use_point }}
                        </span>
                    </div>
                </div>
                {{# } }}

                {{# if(Object.keys(d.coupon_info).length){ }}
                <div class="refund-view-item">
                    <label class="refund-view-item-label">退还优惠券：</label>
                    <div class="refund-view-item-content">
                        {{ d.coupon_info.coupon_name }}
                        （
                        {{# if(d.coupon_info.money > 0){ }}
                        ￥{{ d.coupon_info.money }}
                        {{# }else{ }}
                        {{ d.coupon_info.discount }}折
                        {{# } }}
                        ）
                    </div>
                </div>
                {{# } }}
                {if empty($order_config.do_refund) || $order_config.do_refund == '1' }
                <div class="refund-view-item">
                    <label class="refund-view-item-label">退款方式：</label>
                    <div class="refund-view-item-content">
                        <select name="refund_money_type">
                            <option value="1">原路退款</option>
                            <option value="2">线下退款</option>
                        </select>
                    </div>
                </div>
                {/if}
                <div class="refund-view-item">
                    <label class="refund-view-item-label">退款说明：</label>
                    <div class="refund-view-item-content">
                        <textarea name="shop_refund_remark" class="layui-textarea len-long" maxlength="150"></textarea>
                    </div>
                </div>

            </div>
            <input type="hidden" name="order_goods_id" value="{{ d.order_goods_info.order_goods_id }}"/>
            <button class="layui-btn"  lay-submit id="submit_transfer" lay-filter="submit_transfer" style="display:none;">保存</button>
        </div>
    </div>
</script>

<script>
    var laytpl;
    var form;
    //渲染模板引擎
    layui.use(['laytpl','form'], function(){
        laytpl = layui.laytpl;
        form = layui.form;
        form.render();
    });


    /**
     * 主动退款
     */
    function shopActiveRefund(order_goods_id) {

        $.ajax({
            url: ns.url("shop/orderrefund/getOrderGoodsRefundInfo"),
            type: "POST",
            dataType: "JSON",
            async: false,
            data: {order_goods_id:order_goods_id},
            success: function (res) {
                if(res.code >= 0){
                    //获取模板
                    var getTpl = $("#refund_transfer_html").html();
                    var data = res.data;
                    //渲染模板
                    laytpl(getTpl).render(data, function(html) {
                        layer.open({
                            type: 1,
                            shadeClose: true,
                            shade: 0.3,
                            offset: 'auto',
                            scrollbar: true,
                            fixed: false,
                            title: "店铺主动退款",
                            area: ['700px', 'auto'],
                            btn: ['确认退款', '取消'],
                            yes: function(index, layero){
                                $("#submit_transfer").click();
                            },
                            btn2: function(index, layero){
                                layer.close(index);
                            },
                            content:  html,
                            cancel: function(){
                                //右上角关闭回调
                                //return false 开启该代码可禁止点击该按钮关闭
                            },
                            success: function(layero, index){
                                var repeat_flag = false;//防重复标识
                                form.render();

                                form.on('submit(submit_transfer)', function(data){

                                    if(repeat_flag)return;
                                    repeat_flag = true;
                                    $.ajax({
                                        url: ns.url("shop/orderrefund/shopActiveRefund"),
                                        type: "POST",
                                        dataType: "JSON",
                                        async: false,
                                        data: data.field,
                                        success: function (res) {
                                            layer.msg(res.message);
                                            if(res.code == 0){
                                                layer.close(layer.index - 1);
                                                reloadList();
                                            }else{
                                                repeat_flag = false;
                                            }

                                        }
                                    });
                                    return false;
                                });
                            }
                        });
                        form.render();
                    });
                }else{
                    layer.msg(res.message);
                }
            }
        });

    }
</script>